package com.zbc.zbcservice.service.Impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zbc.zbcservice.mapper.CategoryMapper;
import com.zbc.zbcservice.pojo.Category;
import com.zbc.zbcservice.service.ManageCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ManageCategoryServiceImpl implements ManageCategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public List<Category> findCategoryList() {
        QueryWrapper<Category> queryWrapper = new QueryWrapper<>();
        List<Category> data = categoryMapper.selectList(queryWrapper);
        return data;
    }

    @Override
    public List<Category> ParentCategoryList(Integer parentId) {
        QueryWrapper<Category> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id", parentId);
        List<Category> categoryList = categoryMapper.selectList(queryWrapper);
        return categoryList;
    }

    @Override
    @Transactional
    public void addCategoryForm(Category category) {
        categoryMapper.insert(category);
    }

    @Override
    @Transactional
    public void updateCategory(Category category) {
        categoryMapper.updateById(category);
    }



    @Override
    @Transactional
    public void updateStatus(Category category) {
        categoryMapper.updateById(category);
    }


}
